<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateApplyCollectDataTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /***
         * 填报志愿
         */
        Schema::create('apply_majors', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->comment('学生考试号');
            $table->string('major_code')->comment('志愿代码');
            $table->string('wish_id')->comment('填报志愿顺序');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        /***
         * 宿舍申请
         */
        Schema::create('apply_dorms', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->comment('学生考试号');
            $table->string('apply_reason')->comment('申请原因');
            $table->string('other_reason')->comment('其他原因');
            $table->string('address')->comment('家庭住址');
            $table->string('street')->comment('街道');
            $table->string('detail_address')->comment('详细地址');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        /***
         * 申请延迟军训
         */
        Schema::create('apply_trainings', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->comment('学生考试号');
            $table->string('apply_reason')->comment('申请原因');
            $table->string('other_reason')->comment('其他原因');
            $table->string('attach')->nullable()->comment('附件');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        /***
         * 缴费
         */
        Schema::create('apply_pays', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('exam_code')->comment('学生考试号');
            $table->json('pay_code')->comment('费用项代码(存放数组)');
            $table->decimal('amount')->comment('缴纳费用金额');
            $table->string('out_trade_no')->nullable()->comment('订单号');
            $table->string('transaction_id')->nullable()->comment('支付流水号');
            $table->boolean('status')->default(false)->comment('是否成功缴费');
            $table->integer('type')->comment('缴纳费用方式(1:支付宝 2.微信 3.现场缴费)');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('exam_code')->references('exam_code')->on('basic_new_students')
                ->onDelete('restrict')->onUpdate('cascade');
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('apply_majors');
        Schema::dropIfExists('apply_dorms');
        Schema::dropIfExists('apply_trainings');
        Schema::dropIfExists('apply_pays');
    }
}
